<include file="Public:header" />
<script src="__PUBLIC__/js/PCASClass.js" type="text/javascript"></script>
<style type="text/css">
.add_title{
	padding-bottom:10px;
	height: 60px;
	margin-bottom:15px;
}
.add_title>span{
	border-bottom: 2px solid #1ab394;
	font-size: 24px;
}
.add_body >div >.full-height-scroll{
	border-right:1px dotted #ccc
}
.add_body_title{
	margin:20px auto 20px auto;
	padding-left: 25px;
}
.add_body_form{
	padding-left: 38px;
}
.add_body_form>form>.form-group{
	margin-bottom: 25px;
}
body{overflow-y:hidden;}
.form-control{
	float:left;
}
.checkbox{float:left;}
</style>
<script>
$(function(){
	$(".add_body").height(window.innerHeight-$("#add_body").offset().top-$("#tfoot_div").height()-40);
	$(window).resize(function(){
		$(".add_body").height(window.innerHeight-$("#add_body").offset().top-$("#tfoot_div").height()-40);
	})
})
</script>
<div class="wrapper wrapper-content animated fadeIn col-md-6">
	<include file="Public:alert" />
	<form class="form-horizontal" id="form" role="form" action="{:U('leads/add')}" method="post">
	<div class="ibox-content add_body" id="add_body" style="">
		<div class="row">
			<div class="col-md-12 add_body" style="padding-right: 0px;">
				<div class="full-height-scroll">
					<div class="row" >
						<div class="col-md-12 add_body_title">
							<div class="all-inline">
								<span class="sq-tag"></span>
								<div class="text-tag">
									<span>基础信息</span>
								</div>
							</div>
						</div>
						<div class="col-md-11 add_body_form">
							<volist name="field_list['main']" id="vo" key="key">
								<div class="form-group">
									<label class="col-md-4 control-label">{$vo.name}：</label>
									<if condition="$vo['form_type'] == 'textarea'">
										<if condition = "$vo['tip_start'] eq 1">
											<div class="col-md-6">
												<textarea class="form-control" rows="5"></textarea>
											</div>
											<div class="col-md-2"><span style="color: red;line-height: 32px;margin-left: 10px;">*</span></div>
										<else/>
											<div class="col-md-8">
												<textarea class="form-control" rows="5"></textarea>
											</div>
										</if>
									<elseif condition="$vo['form_type'] == 'address'"/>
										<if condition = "$vo['tip_start'] eq 1">
											<div class="col-md-7">
												{$vo.html}
											</div>
											<div class="col-md-1"><span style="color: red;line-height: 32px;margin-left: 10px;">*</span></div>
										<else/>
											<div class="col-md-8">
												{$vo.html}
											</div>
										</if>
									<elseif condition="$vo['form_type'] == 'box'"/>
										<div class="col-md-6">
											{$vo.html}
										</div>
										<if condition = "$vo['tip_start'] eq 1">
											<div class="col-md-2"><span style="color: red;line-height: 32px;margin-left: 10px;">*</span></div>
										<else/>
											<div class="col-md-2"></div>
										</if>
									<elseif condition="$vo['field'] == 'name'"/>
										<div class="col-md-6">
											<input class="form-control required" id="name" name="name" onkeyup="checkinfo(name)" placeholder="" type="text" />
										</div>
										<div class="col-md-2"><span style="color: red;line-height: 32px;margin-left: 10px;">*</span></div>
									<else/>
										<div class="col-md-6">
											{$vo.html}
										</div>
										<if condition = "$vo['tip_start'] eq 1">
											<div class="col-md-2"><span style="color: red;line-height: 32px;margin-left: 10px;">*</span></div>
										<else/>
											<div class="col-md-2"></div>
										</if>
									</if>
								</div>
							</volist>
						</div>
						<div class="col-md-12 add_body_title">
							<div class="all-inline">
								<span class="sq-tag"></span>
								<div class="text-tag">
									<span>附加信息</span>
								</div>
							</div>
						</div>
						<div class="col-md-11 add_body_form">
							<volist name="field_list['data']" id="vo" key="key">
								<div class="form-group">
									<label class="col-md-4 control-label">{$vo.name}：</label>
									<if condition="$vo['form_type'] == 'address' || $vo['form_type'] == 'box' || $vo['form_type'] == 'textarea'">
										<div class="col-md-7">
											{$vo.html}
										</div>
										<if condition = "$vo['tip_start'] eq 1">
											<div class="col-md-1"><span style="color: red;line-height: 32px;margin-left: 10px;">*</span></div>
										<else/>
											<div class="col-md-1"></div>
										</if>
									<else/>
										<div class="col-md-6">
											{$vo.html}
										</div>
										<if condition = "$vo['tip_start'] eq 1">
											<div class="col-md-2"><span style="color: red;line-height: 32px;margin-left: 10px;">*</span></div>
										<else/>
											<div class="col-md-2"></div>
										</if>
									</if>
								</div>
							</volist>
						</div>
						<div class="col-md-1 pull-right">
							<!-- <div style="height: 100%; border-right: 1px dashed gray;">&nbsp;sadf</div> -->
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div id="tfoot_div" class="clearfix">
		<div class="clearfix" id="tfoot_page">
			<div class="ibox-content" style="border-top: none;">
				<div class="col-sm-offset-2"><button type="submit" id="save_submit" class="btn btn-primary">创建线索</button></div>
			</div>
		</div>
	</div>
	</form>
</div>
<div class="" style="display:none;" id="dialog-validate" title="{:L('VALIDATE_COMPANY_RESULT')}">
	<div id="search_leads_content"></div>
	<div id="search_customer_content"></div>
</div>
<script type="text/javascript">
function checkinfo(param){
	var field_value = $('#'+param).val();
	if(field_value){
		$.post('{:U("leads/checkinfo")}',
			{
				field_value:field_value,
				field_name:param,
			},
			function(data){
				if(data.status == 1){
					$('#'+param+'-error').remove('');
					$('#'+param).after('<label id="'+param+'-error" class="error" for="source"><i class="fa fa-times-circle"></i></label>');
					$('#'+param+'-error').html('<i class="fa fa-times-circle"></i>'+data.data);
				}else{
					$('#'+param+'-error').remove('');
				}
			},
		'json');
	}
}
$(document).ready(function(){
	$('#save_submit').prop('disabled',false);
		/*form表单验证*/
		$("#form").validate({
			submitHandler:function(form){
	            $('#save_submit').click(function(){
					$('#save_submit').prop('disabled',true);
				});
	            form.submit();
	        }    
		});
});
$("[data-type='nummber']").keyup(function(){
	if(isNaN($(this).val())){
		$(this).val($(this).val().replace(/\D/g,''))
	}
});
$("#dialog-validate").dialog({
	autoOpen: false,
	modal: true,
	width: 400,
	maxHeight: 400,
	buttons: { 
		"确定": function () {
			$(this).dialog("close"); 
		}
	},
	position: ["center", 100]
});
$(function(){
	$('#owner_name').click(
		function(){
			$('#dialog-role-list').dialog('open');
			$('#dialog-role-list').load("{:U('user/listDialog')}");
		}
	);
	$('#name').blur(
		function(){
			name = $('#name').val();
			if(name!=''){
				$.post('{:U("leads/check")}',
					{
						name:name
					},
					function(data){
						if(data.data != 0){
							var leads_result = '';
							var customer_result = '';
							if(data.data['leads'].length>0){
								$.each(data.data['leads'], function(k, v){
									leads_result += (k+1)+'、'+v+'</br>';
								});
								$("#search_leads_content").html("<h5>{:L('SAME_LEADS_COMPANY')}</h5>"+leads_result);
							}
							if(data.data['customer'].length>0){
								$.each(data.data['customer'],function(k, v){
									customer_result += (k+1)+'、'+v+'</br>';
								});
								$("#search_customer_content").html("<h5>{:L('SAME_CUSTOMER_COMPANY')}</h5>"+customer_result);
							}
							if(data.data['customer'].length>0 || data.data['leads'].length>0)
								$('#dialog-validate').dialog('open');
							
							
						}
					},
				'json');
			}
		}
	);
});
</script>
<include file="Public:footer" />